package com.wei.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wei.model.ProductCategoryRelDO;
import com.wei.model.ProductDO;
import com.wei.result.R;
import com.wei.service.IProductCategoryRelService;
import com.wei.service.IProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 产品表 前端控制器
 * </p>
 *
 * @author 蔡徐坤
 * @since 2025-07-28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/product")
public class ProductController {

    private final IProductService productService;

    @GetMapping("/find/{id}")
    public R<ProductDO> getById(@PathVariable("id") Long id) {
        return R.ok(productService.getProductById(id));
    }

    @GetMapping("/findAll")
    public R<List<ProductDO>> findAll() {
        return R.ok(productService.findAll());
    }
}
